package com.ruoyi.business.pojo.market;

import com.ruoyi.base.utils.ip.IpUtils;
import com.ruoyi.base.utils.spring.ServletUtils;
import com.ruoyi.business.enums.market.MarketTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.UUID;

/**
 * 市场缓存
 * @author lcf
 */
@Data
@ApiModel
public class MarketCacheQuery {
    /**
     * 标题
     */
    @ApiModelProperty("标题")
    private String title;
    /**
     * 内容
     */
    @ApiModelProperty("内容")
    private String content;
    /**
     * 发布人
     */
    @ApiModelProperty("发布人")
    private String nickName;
    /**
     * 游戏编号
     */
    @ApiModelProperty("游戏编号")
    private String code;
    /**
     * 所在星系
     */
    @ApiModelProperty("所在星系")
    private String galaxy;

    public MarketCacheDTO convert(MarketTypeEnum typeEnum) {
        MarketCacheDTO cache = new MarketCacheDTO();
        cache.setTitle(this.title);
        cache.setContent(this.content);
        cache.setType(typeEnum.getCode());
        cache.setNickName(this.nickName);
        cache.setCode(this.code);
        cache.setDate(new Date());
        cache.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
        cache.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        cache.setGalaxy(this.galaxy);
        return cache;
    }
}
